package com.lanhao.aot.excel;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Random;

import org.apache.commons.io.FileUtils;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;

public class ExcelParseUtil {
	
	private static SimpleDateFormat sdf = new SimpleDateFormat("ssSSS");
	public static String getRandomNo(String prefix) {
		String nextInt = String.valueOf(new Random().nextInt(100));
		if(nextInt.length() < 2) {
			nextInt = "0" + nextInt;
		}
		return prefix + sdf.format(new Date()) + nextInt;
	}
	
	
	public static void main(String[] args) {
//		ExcelReader reader = ExcelUtil.getReader("D://待处理数据.xlsx", 1);
//		List<List<Object>> readAll = reader.read();
//		StringBuilder sb = new StringBuilder();
//		readAll.forEach(lineList -> {
//			String orderNo = (String) lineList.get(0);
//			String bizNo = (String) lineList.get(1);
//			String otherFee = (String) lineList.get(2);
//			sb.append("INSERT INTO t_other_fee_info (order_no, biz_no, other_fee, fuel_rate) VALUES('" + orderNo + "', '"
//					+ bizNo + "', '" + otherFee + "', null);");
//		});
//		
//		try {
//			FileUtils.writeStringToFile(new File("D:/t_other_fee_info.sql"), sb.toString(), "UTF-8");
//		} catch (IOException e) {
//			e.printStackTrace();
//		}
		
		ExcelReader reader = ExcelUtil.getReader("D://最终同步数据.xlsx", 0);
		List<List<Object>> readAll = reader.read();
		List<String> respList = Lists.newArrayList();
		readAll.forEach(lineList -> {
			JSONArray array = new JSONArray();
			String orderNo = (String) lineList.get(0);
			String bizNo = (String) lineList.get(1);
			String rate = (String) lineList.get(2);
			String otherFee = (String) lineList.get(3);
			JSONObject o = new JSONObject();
			o.put("orderNo", orderNo);
			o.put("businessNo", bizNo);
			o.put("newFuelAdditionalRate", rate);
			o.put("newOtherFee", otherFee);
			array.add(o);
			String respBody = HttpRequest.post("http://shipment.anhelogistics.com/smt-integration/inner/doAttachmentfeeSync").body(array.toString()).execute().body();
			respList.add("[" + bizNo + "]" + respBody);
		});
		
		
		try {
			FileUtils.writeLines(new File("D:/sync_response_lines.txt"), respList);
		} catch (IOException e) {
			e.printStackTrace();
		}
		
//		try {
//			FileUtils.writeStringToFile(new File("D:/sync_param.json"), array.toString(), "UTF-8");
//		} catch (IOException e) {
//			e.printStackTrace();
//		}
		
//		String respBody = HttpRequest.post("http://shipment.anhelogistics.com/smt-integration/inner/doAttachmentfeeSync").body(array.toString()).execute().body();
//		
//		try {
//			FileUtils.writeStringToFile(new File("D:/sync_response.txt"), respBody, "UTF-8");
//		} catch (IOException e) {
//			e.printStackTrace();
//		}
		
		
//        
//		try {
//			FileUtils.writeLines(new File("E:/data.txt"), dataList);
//		} catch (IOException e) {
//			e.printStackTrace();
//		}
        
	}
	
}
